package com.zzxx.wechat.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zzxx.wechat.config.CustomDecimalSerialize;
import com.zzxx.wechat.entity.ArcteryxSku;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Data
public class ArcterySkuVo {

    /**
     * 尺码标签
     */
    private String sizeLabel;

    /**
     * 颜色标签
     */
    private String  colourLabel;

    /**
     * 现价
     */
    @JsonSerialize(using = CustomDecimalSerialize.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private BigDecimal discountPrice;

    /**
     * 原价
     */
   // @JsonFormat(pattern = "0.00")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private BigDecimal price;

    /**
     * 库存
     */
    private Integer inventory;
    /**
     * sku名
     */
    private String skuName;

    /**
     * sku图
     */
    private String skuImage;

    public static ArcterySkuVo convert2Vo(ArcteryxSku model) {
        if (model == null) {
            return null;
        }
        ArcterySkuVo result = new ArcterySkuVo();
        BeanUtils.copyProperties(model, result);
        return result;
    }

    public static List<ArcterySkuVo> convert2VoList(List<ArcteryxSku> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream()
                .filter(Objects::nonNull).map(ArcterySkuVo::convert2Vo)
                .collect(Collectors.toList());
    }
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    public BigDecimal getPrice() {
        return price == null ? null : price.setScale(2, BigDecimal.ROUND_HALF_UP);
    }


}
